/**
 * 
 */
package com.myBase.core.modules.goldcoinactivitycashpool.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.myBase.core.entity.GoldcoinActivitycashpool;
import com.myBase.core.facade.service.GoldcoinActivitycashpoolServiceFacade;
import com.myBase.framework.common.config.Global;
import com.myBase.common.persistence.Page;
import com.myBase.framework.common.utils.StringUtils;
import com.myBase.framework.common.web.BaseController;

/**
 * 活动资金池表Controller
 * @author 活动资金池表
 * @version 2017-05-04
 */
@Controller
@RequestMapping(value = "${adminPath}/goldcoinactivitycashpool/goldcoinActivitycashpool")
public class GoldcoinActivitycashpoolController extends BaseController {

    //@Autowired
    private GoldcoinActivitycashpoolServiceFacade goldcoinActivitycashpoolService;

    @ModelAttribute
    public GoldcoinActivitycashpool get(@RequestParam(required = false) String id) {
        GoldcoinActivitycashpool entity = null;
        if (StringUtils.isNotBlank(id)) {
            entity = goldcoinActivitycashpoolService.get(id);
        }
        if (entity == null) {
            entity = new GoldcoinActivitycashpool();
        }
        return entity;
    }

    @RequiresPermissions("goldcoinactivitycashpool:goldcoinActivitycashpool:view")
    @RequestMapping(value = { "list", "" })
    public String list(GoldcoinActivitycashpool goldcoinActivitycashpool, HttpServletRequest request,
            HttpServletResponse response, Model model) {
        Page<GoldcoinActivitycashpool> page = goldcoinActivitycashpoolService
                .findPage(new Page<GoldcoinActivitycashpool>(request, response), goldcoinActivitycashpool);
        model.addAttribute("page", page);
        return "modules/goldcoinactivitycashpool/goldcoinActivitycashpoolList";
    }

    @RequiresPermissions("goldcoinactivitycashpool:goldcoinActivitycashpool:view")
    @RequestMapping(value = "form")
    public String form(GoldcoinActivitycashpool goldcoinActivitycashpool, Model model) {
        model.addAttribute("goldcoinActivitycashpool", goldcoinActivitycashpool);
        return "modules/goldcoinactivitycashpool/goldcoinActivitycashpoolForm";
    }

    @RequiresPermissions("goldcoinactivitycashpool:goldcoinActivitycashpool:edit")
    @RequestMapping(value = "save")
    public String save(GoldcoinActivitycashpool goldcoinActivitycashpool, Model model,
            RedirectAttributes redirectAttributes) {
        if (!beanValidator(model, goldcoinActivitycashpool)) {
            return form(goldcoinActivitycashpool, model);
        }
        goldcoinActivitycashpoolService.save(goldcoinActivitycashpool);
        addMessage(redirectAttributes, "保存活动资金池表成功");
        return "redirect:" + Global.getAdminPath() + "/goldcoinactivitycashpool/goldcoinActivitycashpool/?repage";
    }

    @RequiresPermissions("goldcoinactivitycashpool:goldcoinActivitycashpool:edit")
    @RequestMapping(value = "delete")
    public String delete(GoldcoinActivitycashpool goldcoinActivitycashpool, RedirectAttributes redirectAttributes) {
        goldcoinActivitycashpoolService.delete(goldcoinActivitycashpool);
        addMessage(redirectAttributes, "删除活动资金池表成功");
        return "redirect:" + Global.getAdminPath() + "/goldcoinactivitycashpool/goldcoinActivitycashpool/?repage";
    }

}